/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author A7med
 */
@Entity
@Table(name = "carpenter_offers")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CarpenterOffers.findAll", query = "SELECT c FROM CarpenterOffers c"),
    @NamedQuery(name = "CarpenterOffers.findById", query = "SELECT c FROM CarpenterOffers c WHERE c.id = :id"),
    @NamedQuery(name = "CarpenterOffers.findByCompany", query = "SELECT c FROM CarpenterOffers c WHERE c.company = :company"),
    @NamedQuery(name = "CarpenterOffers.findByCompanyAndProject", query = "SELECT c FROM CarpenterOffers c WHERE c.company = :company and c.parent.project=:project"),
    @NamedQuery(name = "CarpenterOffers.findByAdditions", query = "SELECT c FROM CarpenterOffers c WHERE c.additions = :additions"),
    @NamedQuery(name = "CarpenterOffers.findByOffer", query = "SELECT c FROM CarpenterOffers c WHERE c.offer = :offer")})
public class CarpenterOffers implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "company")
    private String company;
    @Basic(optional = false)
    @NotNull
    @Column(name = "additions")
    private double additions;
    @Basic(optional = false)
    @NotNull
    @Column(name = "offer")
    private double offer;
    @JoinColumn(name = "parent", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Carpenter parent;

    public CarpenterOffers() {
    }

    public CarpenterOffers(Integer id) {
        this.id = id;
    }

    public CarpenterOffers(Integer id, String company, double additions, double offer) {
        this.id = id;
        this.company = company;
        this.additions = additions;
        this.offer = offer;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public double getAdditions() {
        return additions;
    }

    public void setAdditions(double additions) {
        this.additions = additions;
    }

    public double getOffer() {
        return offer;
    }

    public void setOffer(double offer) {
        this.offer = offer;
    }

    public Carpenter getParent() {
        return parent;
    }

    public void setParent(Carpenter parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CarpenterOffers)) {
            return false;
        }
        CarpenterOffers other = (CarpenterOffers) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mycompany.psc.entities.CarpenterOffers[ id=" + id + " ]";
    }
    public double getTotalPrice(){
        return offer+additions;
    }
    public double getPrice(){
        return (1+(parent.getRate()/100))*getTotalPrice();
    }
    public double getFinalPrice(){
        return parent.getQuantity()*getPrice();
    }
    public CarpenterOffers crateCopy(){
        CarpenterOffers copy=new CarpenterOffers();
        copy.setAdditions(additions);
        copy.setCompany(company);
        copy.setOffer(offer);
        return copy;
    }
}
